//
//  ScoreCell.swift
//  Aiwei
//
//  Created by zhu xietong on 2017/11/13.
//  Copyright © 2017年 zhu xietong. All rights reserved.
//

import Foundation
import Eelay
import soapp

public class MallForm {
    public class ScoreField:FieldView,JWStarViewViewDelegate
    {
        public var starV:JWStarView? = nil
        public let nameL = UILabel()
        public override func addLayoutRules() {
            let sv = JWStarView(frame: [0,0,130,16], numberOfStars: 5, rateStyle: .WholeStar, delegate: self)
            sv?.lightColor = UIColor(shex: "#F4CB47")
            sv?.delegate = self
            eelay = [
                [sv!,[ee.T.L.B],130,"16"],
                [nameL,[sv!,ee.R,ee.L,10],[sv!,ee.Y,2]],
            ]
            self.starV = sv
        }
        
        public func starView(_ starView: JWStarView!, currentScore: CGFloat) {
            var pt_num = 0
            switch starView.rateStyle {
            case .HalfStar:
                pt_num = 1
            default:
                break
            }
            mo.model[FK.value] = currentScore.print(num: pt_num)
        }
        public override func mo_model_reload() {
            starV?.currentScore = mo.model[float: FK.value,0]
        }
    }
    
    public class ScoreCell: FieldCell {
        public let starV = ScoreField()
        public override func addLayoutRules() {
            titleL.ui.font14.cl_666.node("title")
            let w = Int(80)
            //        let t = Int(FieldCell.padding_top)
            //        let b = Int(FieldCell.padding_bottom)
            
            let l = Int(FieldCell.padding_left)
            //        let r = Int(FieldCell.padding_right)
            
            
            contentView.eelay = [
                [titleL,[ee.T.L.B,[8,l,-8]],"21",.<w],
                [requiredMark,[titleL,ee.Y,3],[titleL,ee.R,ee.L,2]],
                [__line,[ee.L.B.R,[0,0.0]],"0.5"]
            ]
            self.indicator = .none
            
            __line.backgroundColor = UIColor.clear
            titleL.setContentConstrainToHighLever()
            requiredMark.ui.font18.text("*").text(color: .clear)
            rightIcon.ui.font(size: 13).ncolor(hex: "#aaa")        //        let w = Int(FieldCell.name_width) + 20
            contentView.eelay = [
                [starV,[ee.Y,-1],[titleL,ee.R,ee.L,8],[rightIcon,ee.L,ee.R,-8]],
            ]
            starV.starV?.rateStyle = .WholeStar
        }
        
        public override func mo_model_reload() {
            //        contentView.fillData(model: mo.model)
            titleL.ui.text(mo.model["title",""])
            if let f = DataNode<NSMutableDictionary>.path(node: "\(FK.field)", mo.model)
            {
                starV.mo.model = f
            }
            else
            {
                if let f = DataNode<NSMutableDictionary>.path(node: "\(FK.fields).0", mo.model)
                {
                    starV.mo.model = f
                }
            }
        }
    }
    
    public class ScoreCell1: ScoreCell {
        public override func addLayoutRules() {
            titleL.ui.font14.cl_666.node("title")
            let w = Int(80)
            let l = Int(FieldCell.padding_left)

            contentView.eelay = [
                [titleL,[ee.T.L.B,[12,l,-12]],"21",.<w],
                [requiredMark,[titleL,ee.Y,3],[titleL,ee.R,ee.L,2]],
                [__line,[ee.L.B.R,[0,0.0]],"0.5"]
            ]
            self.indicator = .none

            __line.backgroundColor = UIColor.clear
            titleL.setContentConstrainToHighLever()
            requiredMark.ui.font18.text("*").text(color: .clear)
            rightIcon.ui.font(size: 13).ncolor(hex: "#aaa")        //        let w = Int(FieldCell.name_width) + 20
            contentView.eelay = [
                [starV,[ee.Y,-1],[titleL,ee.R,ee.L,8],[rightIcon,ee.L,ee.R,-8]],
            ]
            starV.starV?.rateStyle = .WholeStar
        }

    }
}

